package com.hoyin.viewtest;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity{

	private class ActivitySkipAdapter {
		private final Context context;
		private final LinearLayout mainLayout;
		private ArrayList<View> viewArrayList = new ArrayList<>();

		ActivitySkipAdapter(Context context, LinearLayout mainLayout) {
			this.context = context;
			this.mainLayout = mainLayout;
		}

		void addButton(Class targetClass, String buttonTag){
			Button button = new Button(context);
			Intent intent = new Intent(context, targetClass);
			button.setText(buttonTag);
			button.setAllCaps(false);
			button.setOnClickListener(view -> {
				startActivity(intent);
			});
			viewArrayList.add(button);
		}

		void activateButtons() {
			for (View view : viewArrayList) {
				mainLayout.addView(view);
			}
			mainLayout.addChildrenForAccessibility(viewArrayList);
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		LinearLayout mainLayout = findViewById(R.id.mainLayout);
		ActivitySkipAdapter activitySkipAdapter = new ActivitySkipAdapter(MainActivity.this, mainLayout);

		activitySkipAdapter.addButton(RoundProgressBarActivity.class, "RoundProgressBar Activity");
		activitySkipAdapter.addButton(TextInputActivity.class, "TextInput Activity");
		activitySkipAdapter.addButton(ToolbarActivity.class, "Toolbar Activity");
		activitySkipAdapter.addButton(CustomLayoutActivity.class, "CustomLayout Activity");
		activitySkipAdapter.addButton(ListViewActivity.class, "ListView Activity");
		activitySkipAdapter.addButton(RecyclerViewActivity.class, "RecyclerView Activity");
		activitySkipAdapter.addButton(FragmentActivity.class, "Fragment Activity");
		mainLayout.post(activitySkipAdapter::activateButtons);
	}
}